#include <iostream>

using namespace std;

class MyCircularDeque {
public:
  MyCircularDeque(int k) {
    front = 0;
    rear = 0;

    capacity = k + 1;

    data = new int[capacity];
  }

  bool insertFront(int value) {
    if (isFull()) {
      return false;
    }

    front = (front - 1 + capacity) % capacity;
    data[front] = value;

    return true;
  }

  bool insertLast(int value) {
    if (isFull()) {
      return false;
    }

    data[rear] = value;
    rear = (rear + 1) % capacity;

    return true;
  }

  bool deleteFront() {
    if (this->isEmpty()) {
      return false;
    }

    front = (front + 1) % capacity;

    return true;
  }

  bool deleteLast() {
    if (this->isEmpty()) {
      return false;
    }

    rear = (rear - 1 + capacity) % capacity;

    return true;
  }

  int getFront() {
    if (this->isEmpty()) {
      return -1;
    }

    return data[front];
  }

  int getRear() {
    if (this->isEmpty()) {
      return -1;
    }

    return data[(rear - 1 + capacity) % capacity];
  }

  bool isEmpty() { return rear == front; }

  bool isFull() { return (rear + 1) % capacity == front; }

private:
  int capacity;

  int *data;
  int front, rear;
};

/**
 * Your MyCircularDeque object will be instantiated and called as such:
 * MyCircularDeque* obj = new MyCircularDeque(k);
 * bool param_1 = obj->insertFront(value);
 * bool param_2 = obj->insertLast(value);
 * bool param_3 = obj->deleteFront();
 * bool param_4 = obj->deleteLast();
 * int param_5 = obj->getFront();
 * int param_6 = obj->getRear();
 * bool param_7 = obj->isEmpty();
 * bool param_8 = obj->isFull();
 */

int main() {
  MyCircularDeque *obj = new MyCircularDeque(3);
  bool param_1 = obj->insertFront(1);
  bool param_2 = obj->insertLast(7);
  bool param_3 = obj->deleteFront();
  bool param_4 = obj->deleteLast();
  int param_5 = obj->getFront();
  int param_6 = obj->getRear();
  bool param_7 = obj->isEmpty();
  bool param_8 = obj->isFull();
}